package com.exchange.websocket.common.huobi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.TimerTask;

/**
 * MoniterTask
 *
 * @author simazilin
 * @date 2018/7/11
 */

public class MoniterTask extends TimerTask {
    public static final Logger log = LoggerFactory.getLogger(MoniterTask.class);
    private long startTime = System.currentTimeMillis();
    private int checkTime = 5000;
    private WebSocketBase client = null;

    public void updateTime() {
        // log.info("startTime is update");
        startTime = System.currentTimeMillis();
    }

    public MoniterTask(WebSocketBase client) {
        this.client = client;
        // log.info("TimerTask is starting.... ");
    }

    @Override
    public void run() {
        if (System.currentTimeMillis() - startTime > checkTime) {
            client.setStatus(false);
            // log.info("Moniter reconnect....... ");
            client.reConnect();
        }
        client.sentPing();
        log.info("Moniter ping data sent.... ");
    }
}
